package com.example.tencentdemo.controller;

import com.example.tencentdemo.DTO.adminMsg;
import com.example.tencentdemo.entity.admin_message;
import com.example.tencentdemo.entity.group_message;
import com.example.tencentdemo.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/msg")
@CrossOrigin
public class msgController {

    @Autowired
    private com.example.tencentdemo.service.Impl.MessageImpl MessageImpl;

    @GetMapping("/group/{group_id}")
    public Result<List<group_message>> getMessagesByGroupId(@PathVariable("group_id") String groupId) {
        try {
            List<group_message> group_messages = MessageImpl.queryByGid(groupId);
            return new Result<>("200", "根据群聊ID查询成功", group_messages);
        } catch (Exception e) {
            return Result.internalServerError("内部服务器错误,删除群聊失败");
        }
    }

    @PostMapping("/admin")
    public Result<List<admin_message>> getAdminMsg(@RequestBody adminMsg adminMsg){
        try {
            List<admin_message> chatRecords = MessageImpl.getChatRecords(adminMsg);
            return new Result<>("200", "查询与管理员的聊天记录成功", chatRecords);
        } catch (Exception e) {
            return Result.internalServerError("内部服务器错误,删除群聊失败");
        }
    }
}
